To create a responsive webpage with a static titlebar and a side menu that is hidden when the screen is too small, you can use HTML, CSS, and JavaScript. Here's an example:
index.html
):html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<script src="script.js" defer></script>
<title>Responsive Webpage</title>
</head>
<body>
<header>
<h1>Title Bar</h1>
<button id="menu-btn">☰</button>
</header>
<nav id="side-menu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<main>
<h2>Welcome to the Responsive Webpage</h2>
<p>This is an example of a responsive webpage with a static title bar and a side menu that is hidden when the screen is too small.</p>
</main>
</body>
</html>
styles.css
):css* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
}
header {
background-color: #333;
display: flex;
justify-content: space-between;
padding: 1rem;
position: fixed;
width: 100%;
z-index: 1;
}
header h1 {
color: white;
margin: 0;
}
button {
background-color: transparent;
border: none;
color: white;
font-size: 1.5rem;
cursor: pointer;
}
#side-menu {
background-color: #f0f0f0;
height: 100%;
left: -200px;
padding: 1rem;
position: fixed;
top: 0;
transition: all 0.3s;
width: 200px;
}
#side-menu ul {
list-style-type: none;
}
#side-menu li {
margin-bottom: 1rem;
}
#side-menu a {
color: #333;
text-decoration: none;
}
main {
margin-left: 1rem;
margin-top: 70px;
padding: 1rem;
}
@media (min-width: 768px) {
#menu-btn {
display: none;
}
#side-menu {
left: 0;
}
}
script.js
):javascriptdocument.getElementById('menu-btn').addEventListener('click', function() {
const sideMenu = document.getElementById('side-menu');
const leftValue = sideMenu.style.left === '0px' ? '-200px' : '0px';
sideMenu.style.left = leftValue;
});
This code will create a responsive webpage with a static title bar and a side menu that is hidden when the screen width is smaller than 768 pixels. When the screen is too small, a menu button will appear in the title bar, and clicking on it will show or hide the side menu.